package com.zhugang.march;

/**
 * @program algorithms
 * @description: drink
 * @author: chanzhugang
 * @create: 2022/03/12 22:41
 */
public class Drink {

    /**
     * 现有x瓶啤酒，每3个空瓶子可以换一瓶啤酒，每7个瓶盖子也可以换一瓶啤酒，问最后可以喝多少瓶瓶酒
     */
    public int drink(int x) {
        // count:瓶酒数；k1:空瓶子； k2：瓶盖子
        int count = x;
        int k1 = x;
        int k2 = x;
        while (k1 >= 3 || k2 >= 7) {
            while (k1 >= 3) {
                int change = k1 / 3;
                count += change;
                k1 %= 3;
                k1 += change;
                k2 += change;
            }
            while (k2 >= 7) {
                int change = k2 / 7;
                count += change;
                k2 %= 7;
                k1 += change;
                k2 += change;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Drink drink = new Drink();

        int count = drink.drink(7);
        System.out.println(count);
    }

}